package com.ruoyi.web.xxj.service.impl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.web.xxj.domain.PaymentInfo;
import com.ruoyi.web.xxj.domain.ProductOrder;
import com.ruoyi.web.xxj.domain.vo.EachMonthSumObj;
import com.ruoyi.web.xxj.domain.vo.PaymentInfoVo;
import com.ruoyi.web.xxj.mapper.PaymentInfoMapper;
import com.ruoyi.web.xxj.mapper.ProductOrderMapper;
import com.ruoyi.web.xxj.service.IPaymentInfoService;

import lombok.extern.slf4j.Slf4j;

/**
 * 支付流水Service业务层处理
 *
 * @author ruoyi
 * @date 2024-01-27
 */
@Slf4j
@Service
public class PaymentInfoServiceImpl implements IPaymentInfoService {
    @Autowired
    private PaymentInfoMapper paymentInfoMapper;
    @Autowired
    private ProductOrderMapper productOrderMapper;

    /**
     * 查询支付流水
     *
     * @param id 支付流水主键
     * @return 支付流水
     */
    @Override
    public PaymentInfo selectPaymentInfoById(Long id) {
        return paymentInfoMapper.selectPaymentInfoById(id);
    }

    /**
     * 查询支付流水列表
     *
     * @param paymentInfo 支付流水
     * @return 支付流水
     */
    @Override
    public List<PaymentInfoVo> selectPaymentInfoList(PaymentInfo paymentInfo) {
    	List<PaymentInfoVo> list = paymentInfoMapper.selectPaymentInfoList(paymentInfo);
    	for (PaymentInfoVo pvo : list) {
			List<ProductOrder> orders = productOrderMapper.getPOrdersByFindInIds(pvo.getProductOrderIds());
			pvo.setProductOrders(orders);
		}
        return list;
    }

    /**
     * 新增支付流水
     *
     * @param paymentInfo 支付流水
     * @return 结果
     */
    @Override
    public int insertPaymentInfo(PaymentInfo paymentInfo) {
        return paymentInfoMapper.insertPaymentInfo(paymentInfo);
    }

    /**
     * 修改支付流水
     *
     * @param paymentInfo 支付流水
     * @return 结果
     */
    @Override
    public int updatePaymentInfo(PaymentInfo paymentInfo) {
        return paymentInfoMapper.updatePaymentInfo(paymentInfo);
    }

    /**
     * 批量删除支付流水
     *
     * @param ids 需要删除的支付流水主键
     * @return 结果
     */
    @Override
    public int deletePaymentInfoByIds(Long[] ids) {
        return paymentInfoMapper.deletePaymentInfoByIds(ids);
    }

    /**
     * 删除支付流水信息
     *
     * @param id 支付流水主键
     * @return 结果
     */
    @Override
    public int deletePaymentInfoById(Long id) {
        return paymentInfoMapper.deletePaymentInfoById(id);
    }

    @Override
    public BigDecimal getToYearPayment() {
        return paymentInfoMapper.getToYearPayment();
    }

    @Override
    public List<EachMonthSumObj> getEachMonthPayment(String type) {
        return paymentInfoMapper.getEachMonthPayment(type);
    }
}
